# -*- coding: utf-8 -*-

import json


class AIUI:
    def __init__(self):
        pass

    # AIUI配置
    @staticmethod
    def aiui_configure(appid, key, boolean):
        data = {
            'type': 'aiui_msg',
            'content': {
                'login': {
                    'appid': appid,
                    'key': key
                },
                'launch': boolean
            }
        }
        data = json.dumps(data)
        return data

    # AIUI控制
    @staticmethod
    def aiui_control(msg_type):
        data = {
            "type": "aiui_msg",
            "content": {
                "msg_type": msg_type,
                "arg1": 0,
                "arg2": 0,
                "params": ""
            }
        }
        data = json.dumps(data)
        return data

    # 控制AIUI播放
    @staticmethod
    def voice_control(boolean):
        data = {
            "type": "voice",
            "content": {
                "enable_voice": boolean  # 是否禁止AIUI声音播放
            }
        }
        data = json.dumps(data)
        return data

    # WIFI状态查询
    @staticmethod
    def wifi_status():
        data = {
            "type": "status",
            "content": {
                "query": "wifi"  # 查询AIUI WIFI状态信息
            }
        }
        return json.dumps(data)

    # 音频保存
    @staticmethod
    def audio_save(save_len):
        data = {
            "type": "save_audio",
            "content": {
                "save_len": save_len  # 通过save_len指定保存音频时长，单位为秒
            }
        }
        data = json.dumps(data)
        return data

    # 开始声音合成
    @staticmethod
    def tts_start(text, emot):
        data = {
            "type": "tts",
            "content": {
                "action": "start",  # 开始合成
                "text": text,  # 需要合成播放的文本(注意文本的编码格式要为utf-8)
                "parameters": {
                    "emot": emot,  # emot值为neutral，happy，sorrow中一个
                    "xxx": "xxx"  # TTS支持设置的其他参数
                }
            }
        }
        data = json.dumps(data)
        return data

    # 停止始声音合成
    @staticmethod
    def tts_end():
        data = {
            "type": "tts",
            "content": {
                "action": "stop"  # 停止合成
            }
        }
        data = json.dumps(data)
        return data

    # SmartConfig 模式开启
    @staticmethod
    def smart_config(timeout):
        data = {
            "type": "smartcfg",
            "content": {
                "cmd": "start",
                "timeout": timeout  # 接收smartconfig配置的超时时间
            }
        }
        data = json.dumps(data)
        return data

    # SmartConfig 模式关闭
    @staticmethod
    def smart_config():
        data = {
            "type": "smartcfg",
            "content": {
                "cmd": "stop"
            }
        }
        data = json.dumps(data)
        return data
